#!/bin/sh

test_description="test unsupported proc-receive version"

. ./lib/sharness.sh

packet_flush () {
	printf "0000"
}

test_expect_success "create pipe" '
        mkfifo pipe
'
 
do_receive_pack_1 () {
	output1="000fversion=200" &&
	output2="0000" &&
	printf >&2 "> $output1\n" &&
	printf >&2 "> $output2\n" &&
	printf "$output1" && printf "$output2\n" && exit
}

test_expect_success "unsupport version number 200" "
        (
		do_receive_pack_1 <pipe | \
                test_must_fail proc-receive --mock >pipe
	) >actual 2>&1 &&
        cat >expect <<-EOF &&
> 000fversion=200
> 0000
proc-receive: version '200' is not supported
EOF
	test_cmp expect actual
"

do_receive_pack_2 () {
	output1="0010version=200" &&
	output2="0000" &&
	printf >&2 "> $output1\n" &&
	printf >&2 "> $output2\n" &&
	printf "$output1\n" && printf "$output2\n" && exit
}

test_expect_success "unsupport version number with LF" "
        (
		do_receive_pack_2 <pipe | \
                test_must_fail proc-receive --mock >pipe
	) >actual 2>&1 &&
        cat >expect <<-EOF &&
> 0010version=200
> 0000
proc-receive: version '200' is not supported
EOF
	test_cmp expect actual
"


do_receive_pack_3 () {
	output="0024version=200\0atomic push-options\n" &&
  output2="0000" &&
#	printf >&2 "> $output" &&
#  printf >&2 "> $output2\n" &&
	printf "$output"  && printf "$output2\n" && exit
}

test_expect_success "unsupport version number with capabilities" "
        (
		do_receive_pack_3 <pipe | \
                test_must_fail proc-receive --mock >pipe
	) >actual 2>&1 &&
        cat >expect <<-EOF &&
	proc-receive: version '200' is not supported
	EOF
	test_cmp expect actual
"


do_receive_pack_4 () {
	output="0023version=200\0atomic push-options" &&
	output2="0000" &&
	printf "$output"  && printf "$output2\n" && exit

}

test_expect_success "unsupport version number with capabilities (no LF)" "
        (
		do_receive_pack_4 <pipe | \
                test_must_fail proc-receive --mock >pipe
	) >actual 2>&1 &&
        cat >expect <<-EOF &&
	proc-receive: version '200' is not supported
	EOF
	test_cmp expect actual
"

test_done
